//
//  NSArray+Filter.m
//  searchController
//
//  Created by mac on 16/10/26.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "NSArray+Filter.h"

@implementation NSArray (Filter)

- (NSArray *)filter:(FilterArrayBlock)block
{
    NSMutableArray *arr = [NSMutableArray new];
    for(id obj in self)
    {
        if (block(obj))
        {
            [arr addObject:obj];
        }
    }
    return arr;
}

- (NSArray *)filter:(ForEach)each mapBlock:(Map)mBlock
{
    NSMutableArray *arr = [NSMutableArray new];
    for(NSString *obj in self)
    {
        for(NSInteger i = 0; i < obj.length; i++)
        {
            if(each(obj,i))
            {
                [arr addObject:mBlock(obj,i)];
            }
        }
    }
    return arr;
}
@end
